 <?php 
  try {  	
  $form = $_POST['form'];
  $EmployeecontactsUid = $form['EMPLOYEECONTACTS_UID'];
  $EmployeeId = $form['EMPLOYEE_ID'];
  $Firstname = $form['FIRSTNAME'];
  $Lastname = $form['LASTNAME'];
  $RelationshipId = $form['RELATIONSHIP_ID'];
  $Spouse = $form['SPOUSE'];
  $Dependent = $form['DEPENDENT'];
  $Beneficiary = $form['BENEFICIARY'];
  $Emergencycontact = $form['EMERGENCYCONTACT'];
  $Homephone = $form['HOMEPHONE'];
  $Mobilephone = $form['MOBILEPHONE'];
  $Email = $form['EMAIL'];
  $Address1 = $form['ADDRESS1'];
  $Address2 = $form['ADDRESS2'];
  $City = $form['CITY'];
  $StateId = $form['STATE_ID'];
  $Zipcode = $form['ZIPCODE'];
  $Dateofbirth = $form['DATEOFBIRTH'];

  require_once ( PATH_PLUGINS . 'hr' . PATH_SEP . 'class.hr.php');
  $pluginObj = new hrClass ();

  require_once ( "classes/model/HrEmployeeContacts.php" );

     //if exists the row in the database propel will update it, otherwise will insert.
     $tr = HrEmployeeContactsPeer::retrieveByPK( $EmployeecontactsUid );
     if ( ! ( is_object ( $tr ) &&  get_class ($tr) == 'HrEmployeeContacts' ) ) {
       $tr = new HrEmployeeContacts();
     }
     $tr->setEmployeecontactsUid( $EmployeecontactsUid );
     $tr->setEmployeeId( $EmployeeId );
     $tr->setFirstname( $Firstname );
     $tr->setLastname( $Lastname );
     $tr->setRelationshipId( $RelationshipId );
     $tr->setSpouse( $Spouse );
     $tr->setDependent( $Dependent );
     $tr->setBeneficiary( $Beneficiary );
     $tr->setEmergencycontact( $Emergencycontact );
     $tr->setHomephone( $Homephone );
     $tr->setMobilephone( $Mobilephone );
     $tr->setEmail( $Email );
     $tr->setAddress1( $Address1 );
     $tr->setAddress2( $Address2 );
     $tr->setCity( $City );
     $tr->setStateId( $StateId );
     $tr->setZipcode( $Zipcode );
     $tr->setDateofbirth( $Dateofbirth );

     if ($tr->validate() ) {
       // we save it, since we get no validation errors, or do whatever else you like.
       $res = $tr->save();
     }
     else {
       // Something went wrong. We can now get the validationFailures and handle them.
       $msg = '';
       $validationFailuresArray = $tr->getValidationFailures();
       foreach($validationFailuresArray as $objValidationFailure) {
         $msg .= $objValidationFailure->getMessage() . "<br/>";
       }
       //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
     }
    //return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');

    //to do: uniform  coderror structures for all classes
  
  //if ( $res['codError'] < 0 ) {
  //  G::SendMessageText ( $res['message'] , 'error' );  
  //}
  G::Header('location: hrEmployeeContactsListSS');   
  
  }
  catch ( Exception $e ) {
    $G_PUBLISH = new Publisher;
    $aMessage['MESSAGE'] = $e->getMessage();
    $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
    G::RenderPage( 'publish', 'blank' );
  }      
   